<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>用户角色分配</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="/dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="/plugins/iCheck/flat/blue.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="/plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="/plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="/plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="/js/html5shiv.min.js"></script>
    <script src="/js/respond.min.js"></script>
    <![endif]-->

    <script>
        function selectAll() {
            if (document.getElementById("par0").checked == true) {
                for (var i = 0; i < $('.func').length; i++) {
                    $('.func')[i].checked = true;
                }
            } else {
                $('.func').attr("checked", false);
            }
        }

        function select(id) {
            if (document.getElementById("role" + id).checked == false) {
                document.getElementById("role" + id).checked = true;
            } else {
                $("#role" + id).attr("checked", false);
            }
        }


        function submitTable() {
            var idArray = [];
            for (var i = 0; i < $('.func').length; i++) {
                if ($('.func')[i].checked == true) {
                    idArray.push($('.func')[i].value);
                }
            }
            var parameter = {};
            parameter.roleIds = idArray;
            parameter.userId = '<%=request.getParameter("id")%>';

            $.ajax({
                type: "POST",
                url: "/userRoleInsert",
                data: JSON.stringify(parameter),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    alert(result);
                    window.location.reload();
                },
                error: function (msg) {
                    alert(msg.responseText);
                    window.location.reload();
                }
            });
        }
    </script>
<body class="skin-blue sidebar-mini wysihtml5-supported">
<jsp:include page="header.jsp"/>
<jsp:include page="menu.jsp"/>

<div class="content-wrapper">
    <section class="content-header">
        <h1>
            用户角色分配
        </h1>
        <ol class="breadcrumb">
            <li><a href="${firstMenuUrl}"><i class="fa fa-dashboard"></i>${firstMenuName}</a></li>
            <li><a href="${secMenuUrl}"><i class="fa fa-dashboard"></i>${secMenuName}</a></li>
            <li class="active">用户角色分配</li>
        </ol>
    </section>

    <section class="content">
        <div class="box">
            <div><input type="checkbox" onclick="selectAll()" id="par0"/><span onclick="select(0)">全选</span>
            </div>
            <c:if test="${userRoleList != null}">
                <c:forEach var="item" items="${userRoleList}" varStatus="status">
                    <div style="padding-left:60px">
                        <input id="role${item.roleId}" type="checkbox" value="${item.roleId}"
                               onclick="setRoleRight(this)" class="func"
                               <c:if test="${item.selected == true}">checked="true"</c:if>
                               style="padding-left:50px"/><span
                            onclick="select(${item.roleId})">${item.roleDesc}-${item.roleName}</span>

                    </div>
                </c:forEach>
            </c:if>
            <div class="box-footer">
                <button type="submit" class="btn btn-info pull-right" onclick="submitTable()">提交</button>
            </div>

        </div>
    </section>
</div>


</div>

<!-- jQuery 2.1.4 -->
<script src="/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="/js/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<!-- Bootstrap 3.3.5 -->
<script src="/bootstrap/js/bootstrap.min.js"></script>
<!-- Sparkline -->
<script src="/plugins/sparkline/jquery.sparkline.min.js"></script>
<!-- jvectormap -->
<script src="/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<!-- jQuery Knob Chart -->
<script src="/plugins/knob/jquery.knob.js"></script>
<!-- daterangepicker -->
<script src="/js/moment.min.js"></script>
<script src="/plugins/daterangepicker/daterangepicker.js"></script>
<!-- datepicker -->
<script src="/plugins/datepicker/bootstrap-datepicker.js"></script>
<!-- Bootstrap WYSIHTML5 -->
<script src="/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<!-- Slimscroll -->
<script src="/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="/plugins/fastclick/fastclick.min.js"></script>
<!-- AdminLTE App -->
<script src="/dist/js/app.min.js"></script>
</body>
</html>